<?php
/**
* This is a representation of a record in DB
* @author Charly Aguirre M. <charagmz@gmail.com>
* @version 1.0
* @package Record
*/

class Record
{
    private $dbinterface;
    
    /**
    * Constructor function
    */
    function __construct()
    {
        $this->dbinterface = new DBInterface();
    }
    
    /**
    * Insert a record old in the DB
    * @param Array $data An associative array with the player data
    * @return Bool Indicates if the insertion was succesful
    */
    function create($data)
    {
        return $this->dbinterface->exec_insert($data,'record');
    }
    
    /**
    * Delete a record
    * @param Integer $id Id of the record to be deleted
    */
    function remove($id)
    {
        $this->dbinterface->exec_delete('record','rec_id='.$id);
    }
    
    /**
    * Retrieve the information of one record
    * @param Integer $id Id of the record
    * @return Array Array with the record data
    */
    function getData($id)
    {
        $table = array('record','player','delegation');
        $fields = array('rec_id','rec_status','pla_first_name','pla_last_name', 'rec_type',
                        'rec_ambit', 'to_char(rec_date,\'YYYY.MM.DD\') as record_date',
                        'rec_description', 'rec_value', 'rec_gender', 'rec_rec_id', 'del_name as delegation');
        $criteria = 'rec_id='.$id.' and rec_pla_id=pla_id and del_id=pla_del_id';
        $result_set = $this->dbinterface->exec_select($fields,$table,$criteria);
        return $result_set[0];
    }
    
    /**
    * Retrieve a list of all records accord
    * @return Array Bidimensional array with the players data
    */
    function getList()
    {
        $fields = array('rec_id', 'rec_type', 'rec_ambit', 'rec_value', 'rec_gender');
        $criteria = 'rec_status=1';
        return $this->dbinterface->exec_select($fields,'record',$criteria);
    }
}

?>

